﻿using LanguagePolish.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LanguagePolish.EntityModel
{
    partial class TeacherAvailability : BaseViewModelErrorInfo     // добавляем возможность использования оповещения.
    {
        public override void CreateRules()
        {
            AddRule("DtTimeFrom1", () => TimeFrom1.HasValue && TimeTo1.HasValue && TimeFrom1.Value > TimeTo1.Value, "Start must be before End");
            AddRule("DtTimeTo1", () => TimeFrom1.HasValue && TimeTo1.HasValue && TimeFrom1.Value > TimeTo1.Value, "End must be after Start");
            AddRule("DtTimeFrom2", () => TimeFrom2.HasValue && TimeTo2.HasValue && TimeFrom2.Value > TimeTo2.Value, "Start must be before End");
            AddRule("DtTimeTo2", () => TimeFrom2.HasValue && TimeTo2.HasValue && TimeFrom2.Value > TimeTo2.Value, "End must be after Start");
        }
        
        /// <summary>
        /// Конвертор TimeSpan в DateTime и наоборот
        /// </summary>
        public DateTime DtTimeFrom1 
        {
            get 
            {
                if (TimeFrom1.HasValue)
                    return Convert.ToDateTime(TimeFrom1.Value.ToString());
                else
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
            }
            set 
            {
                if (value == null)
                    TimeFrom1 = null;
                TimeFrom1 = value.TimeOfDay; 
            }
        }

        public DateTime DtTimeFrom2
        {
            get
            {
                if (TimeFrom2.HasValue)
                    return Convert.ToDateTime(TimeFrom2.Value.ToString());
                else
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
            }
            set
            {
                if (value == null)
                    TimeFrom2 = null;
                TimeFrom2 = value.TimeOfDay;
            }
        }

        public DateTime DtTimeTo1
        {
            get
            {
                if (TimeTo1.HasValue)
                    return Convert.ToDateTime(TimeTo1.Value.ToString());
                else
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
            }
            set
            {
                if (value == null)
                    TimeTo1 = null;
                TimeTo1 = value.TimeOfDay;
            }
        }

        public DateTime DtTimeTo2
        {
            get
            {
                if (TimeTo2.HasValue)
                    return Convert.ToDateTime(TimeTo2.Value.ToString());
                else
                    return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
            }
            set
            {
                if (value == null)
                    TimeTo2 = null;
                TimeTo2 = value.TimeOfDay;
            }
        }



    }
}
